package com.think.teaching.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.think.teaching.mapper.QuestionAnswerMapper;
import com.think.teaching.model.QuestionAnswer;
import com.think.teaching.service.QuestionAnswerService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 参考答案 服务实现类
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
@Service
public class QuestionAnswerServiceImpl extends BaseServiceImpl<QuestionAnswerMapper, QuestionAnswer> implements QuestionAnswerService {

	@Override
	public QuestionAnswer AddQuestionAnswer(QuestionAnswer answer) {
		if (this.save(answer)) {
			return answer;
		}
		return null;
	}



	@Override
	public QuestionAnswer UpdateQuestionAnswer(QuestionAnswer answer) {
		if (this.updateById(answer)) {
			return answer;
		}
		return null;
	}

	@Override
	public QuestionAnswer GetQuestionAnswer(Integer id) {
		QueryWrapper<QuestionAnswer> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", id).eq("state", 1).ne("delflag", 1);
		return getOne(queryWrapper);
	}

	@Override
	public QuestionAnswer SetQuestionAnswerState(Integer id, Integer state) {
		UpdateWrapper<QuestionAnswer> queryWrapper = new UpdateWrapper<>();
		queryWrapper.eq("id", id).ne("delflag", 1).set("state", state);
		this.update(queryWrapper);
		return getById(id);
	}

}
